﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CalendarApplication
{
    public partial class ucCalendarContainer : UserControl
    {
        DateTime dt;
        ucCalendarContainer _cal;

        public ucCalendarContainer()
        {
            InitializeComponent();
            dt = DateTime.Now;
            PaintNewPanel();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //go backwards a month
            dt = dt.AddMonths(-1);
            PaintNewPanel();
        }//end back button

        private void toolStripButton3_Click(object sender, EventArgs e)//next button
        {
            //go forward month
            dt = dt.AddMonths(1);
            PaintNewPanel();
        }//end forward

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            //back to current month
            dt = DateTime.Now;
            PaintNewPanel();
        }//end refresh button

        public void PaintNewPanel()
        {
            //cursor waiting
            this.Cursor = Cursors.WaitCursor;
            //clear controls from panel
            panel1.Controls.Clear();
            panel1.Refresh();

            //restarting paint
            ucCalendarPallette uc = new ucCalendarPallette(dt, this);
            uc.Dock = DockStyle.Fill;
            panel1.Controls.Add(uc);
            toolStripLabel1.Text = dt.ToString("MMMM") + " " + dt.ToString("yyyy");
            //reset cursor
            this.Cursor = Cursors.Default;
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            //private variable calendar
            _cal = this;
            //add appointment via setter instead of day
            //calls appointment form in modal 
            frmAddAppointment frm = new frmAddAppointment(dt, _cal);
            frm.ShowDialog();
        }
    }
}
